package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendanceDataRecordAddDTO;
import org.jsola.hr.dto.AttendanceDataRecordUpdateDTO;
import org.jsola.hr.entity.AttendanceDataRecordDO;
import org.jsola.hr.query.AttendanceDataRecordQuery;
import org.jsola.hr.service.IAttendanceDataRecordService;
import org.jsola.hr.vo.AttendanceDataRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 考勤导入记录表
 *
 * @author zhr
 */
@Component
public class AttendanceDataRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendanceDataRecordService attendanceDataRecordService;

    /**
     * 生成add测试数据
     * @return AttendanceDataRecordAddDTO
     */
    public AttendanceDataRecordAddDTO getAttendanceDataRecordAddDTO(){
        AttendanceDataRecordAddDTO attendanceDataRecordAddDTO = new AttendanceDataRecordAddDTO();
        attendanceDataRecordAddDTO.setIsHandle(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendanceDataRecordAddDTO.setIsImport(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendanceDataRecordAddDTO.setSalaryTemplateSalaryId(getRandomValue("varchar",50));
        attendanceDataRecordAddDTO.setYear(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceDataRecordAddDTO.setMonth(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceDataRecordAddDTO.setAttendanceSallaryTemplateId(getRandomValue("varchar",50));
        attendanceDataRecordAddDTO.setFileName(getRandomValue("varchar",100));
        attendanceDataRecordAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendanceDataRecordAddDTO.setStartTime((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        attendanceDataRecordAddDTO.setEndTime((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        attendanceDataRecordAddDTO.setDataType(getRandomValue("varchar",32));
        return attendanceDataRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendanceDataRecordUpdateDTO
     */
    public AttendanceDataRecordUpdateDTO getAttendanceDataRecordUpdateDTO(AttendanceDataRecordVO attendanceDataRecordVO){
        return attendanceDataRecordService.selectDOById(attendanceDataRecordVO.getId(), SITE_ID).to(AttendanceDataRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendanceDataRecordQuery
     */
    public AttendanceDataRecordQuery getAttendanceDataRecordQuery() {
        AttendanceDataRecordQuery attendanceDataRecordQuery = new AttendanceDataRecordQuery();
        List<AttendanceDataRecordDO> attendanceDataRecordDOList = attendanceDataRecordService.list(new AttendanceDataRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendanceDataRecordDOList)) {
            AttendanceDataRecordDO attendanceDataRecordDO = attendanceDataRecordDOList.get(0);
            attendanceDataRecordQuery = attendanceDataRecordDO.to(AttendanceDataRecordQuery.class);
        }
        return attendanceDataRecordQuery;
    }

    /**
     * 保存示例
     * @return AttendanceDataRecordVO
     */
    public AttendanceDataRecordVO saveAttendanceDataRecordExample(){
        AttendanceDataRecordAddDTO addDTO = this.getAttendanceDataRecordAddDTO();
        AttendanceDataRecordVO attendanceDataRecordVO = attendanceDataRecordService.save(addDTO,buildTokenUser());
        return attendanceDataRecordVO;
    }


}

